<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('路线信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
<!--                        <ul>-->
<!--                          -->
<!--                            <li>-->
<!--                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>-->
<!--                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>-->
<!--                            </li>-->
<!--                        </ul>-->
                        <input type="hidden" id="routeId" th:value="${routeId}"/>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="close1()">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="inspection:info:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="inspection:info:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('inspection:info:edit')}]];
        var removeFlag = [[${@permission.hasPermi('inspection:info:remove')}]];
        var prefix = ctx + "inspection/info";

        $(function() {
            var options = {
                url: prefix + "/list?routeId="+$("#routeId").val(),
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "路线信息",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '数据状态',
                    visible: false
                },

                {
                    field : 'inspectionId', 
                    title : '巡检点id'
                },
                  {
                        field : 'name',
                        title : '巡检点'
                    },
                    {
                        field : 'sort',
                        title : '排序',
                        formatter: function (value, row, index) {
                            return '<input id="bian'+row.id+'" onBlur="sort(\''+row.id+'\')"  value="'+row.sort+'"  class="form-control" style="width:80px;">';
                        }
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="close1()"></i>新增</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function sort(id){
            var sort=$("#bian"+id).val();
            console.log(sort);
            var idval=id;
            $.ajax({url:"/inspection/info/dianUpdate",type:"post",data:"id="+idval+"&sort="+sort,async:true,success:function (reslut) {
                    if (reslut.code=="0") {
                        setTimeout(function(){
                        } ,1000)
                        //再执行关闭
                    }else{
                        layer.msg("添加失败", {icon: 2});
                    }
                },error:function (reslut) {
                    layer.msg("操作失败", {icon: 2});
                }
            });
        }


        function close1(){
            var routeId=$("#routeId").val();
            var index = layer.open({
                type: 2,
                area: [800+ 'px', ($(window).height()-20 ) + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "巡检点",
                content: prefix+"/dian?routeId="+routeId,
                btn: ['确定', '关闭'],
                // 弹层外区域关闭
                shadeClose: true,
                yes: addResult,
                cancel: function(index) {
                    return true;
                },
                callBack: addResult
            });
        }
        function  addResult(index, layero) {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            layer.close(index);
        }


        function close2(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //layer.msg(index);
            parent.layer.close(index); //再执行关闭
        }
    </script>
</body>
</html>